﻿@using Company.Project.Application.Service.CacheService
@using Company.Project.Domain.Model.DTO.Manager
@using Company.Project.Web.Admin.Areas.Admin.Lib
@using Microsoft.AspNetCore.Http
@using Microsoft.Extensions.DependencyInjection
@model LoginUserDTO
@{
    //解析
    var controllerName = ViewContext.RouteData.Values["controller"].ToString().ToLower();
    var actionName = ViewContext.RouteData.Values["action"].ToString().ToLower();
    var areaName = ViewContext.RouteData.Values["area"].ToString().ToLower();
    var nav = Model.UserActionList.Select(x => x.ModuleDtos).Aggregate<IEnumerable<RoleAction_ModuleDTO>>((a, b) => a.Concat(b)).FirstOrDefault(x => x.controllerName == controllerName && x.areaName == areaName && x.actionName == actionName);
    var btn = "";
}
@{
    if (nav != null)
    {
        Model.UserActionList.Where(x => x.ModuleID == nav.ModuleID).ToList().ForEach(x =>
        {
            x.ModuleDtos.Where(y => !y.ShowEnum).OrderBy(y => y.OrderId).ToList().ForEach(z =>
            {
                if (z.ActionFun != "EditItem" && z.ActionFun != "")
                {
                    if (z.ActionFun == "DelItem")
                    {
                        btn += "<script type=\"text/javascript\">var multiselect = true;</script>";
                    }
                    btn += "<div onclick=\"" + z.ActionFun + "('" + z.ActionUrl + "')\" class=\"btn btn-info btn-white\"><i class=\"ui-icon ace-icon fa " + z.ActionCls + "\"></i>" + z.ModuleActionName + "</div>";
                }
                else if (z.ActionFun == "EditItem")
                {
                    //将编辑按钮移入grid内部 edit by 2017.2.4
                    btn += "<script type=\"text/javascript\">var pEditUrl = '" + z.ActionUrl + "';var pEdit = true;</script>";
                }
            });
            if (!x.ModuleDtos.Exists(y => y.ActionFun == "EditItem"))
            {
                btn += "<script type=\"text/javascript\">var pEditUrl = '';var pEdit = false;</script>";
            }
            if (!x.ModuleDtos.Exists(y => y.ActionFun == "DelItem"))
            {
                btn += "<script type=\"text/javascript\">var multiselect = false;</script>";
            }
        });
    }
    else
    {
        btn += "<script type=\"text/javascript\">var pEditUrl = '';var pEdit = false;</script>";
        btn += "<script type=\"text/javascript\">var multiselect = false;</script>";
    }
    if (!string.IsNullOrEmpty(ViewBag.Back))
    {
        btn += "<div class=\"btn btn-info btn-white\" onclick=\"location.href='" + @ViewBag.Back + "'\"><i class=\"ui-icon ace-icon fa light-orange fa-reply\"></i>返回</div>";
    }
}
<style type="text/css">
    .ButtonPanle {
        margin-bottom: 10px;
        line-height: 42px;
    }
</style>
<div class="ButtonPanle btn-group">
    @Html.Raw(btn)
</div>
